t = int(input())
for _ in range(t):
x, y ,k = map(int, input().split())
while k > 0:
if(x == 1 ):
x += k % (y - 1)
k = 0
if( (x // y + 1 ) * y - x > k):
x+=k
k = 0
else:
k = k - ((x // y + 1 ) * y - x)
x = (x // y + 1 ) * y
while x % y == 0 :
x = x//y
print(x)
Going to office | Color the boxes |
Missing numbers | Maximum sum |
13 Reasons Why | Friend's Relationship |
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |